import 'package:flutter/material.dart';
import 'package:yuan_hang_app/res/w_colors.dart';
import 'package:yuan_hang_app/utils/size_utils.dart';
import 'package:yuan_hang_app/widget/w_text.dart';

class StatusBtn extends StatelessWidget {
  final Color color;
  final Color? fontColor;
  final String text;
  final double? height;
  final double width;
  final double radius;
  final double fontSize;
  final double paddingHorizontal;
  final EdgeInsetsGeometry? margin;
  final bool isBg;
  final Function? onLongPress;
  final Function? onPressed;
  final bool isItemBtn;
  final bool isTag;
  final String? icon;

  const StatusBtn({
    super.key,
    this.text = "",
    this.height,
    this.width = 50,
    this.radius = 5,
    this.fontSize = 12,
    this.color = WColors.primaryColor,
    this.fontColor,
    this.paddingHorizontal = 5,
    this.margin,
    this.icon,
    this.isBg = false,
    this.isItemBtn = false,
    this.isTag = false,
    this.onLongPress,

    this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    double h = height == null
        ? isItemBtn
            ? 32
            : 28
        : height!;
    return GestureDetector(
      onTap: () {
        if (onPressed != null) {
          onPressed!();
        }
      },
      onLongPress: (){
        if(onLongPress!=null){
          onLongPress!();
        }
      },
      child: Container(
          height: h.px,
          // width: width.px,
          alignment: Alignment.center,
          margin: margin,
          padding: EdgeInsets.symmetric(horizontal: paddingHorizontal.px),
          constraints: BoxConstraints(minWidth: width.px),
          decoration: BoxDecoration(
              border: isBg || isTag
                  ? const Border()
                  : Border.all(color: color, width: 1.px),
              color: isTag
                  ? color.withOpacity(0.2)
                  : isBg
                      ? color
                      : WColors.white,
              borderRadius:
                  BorderRadius.circular(isItemBtn ? h.px : radius.px)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              if (icon != null)
                Padding(
                  padding: EdgeInsets.only(right: 5.px),
                  child: Image.asset(
                    "images/$icon",
                    height: 16.px,
                    color: color,
                  ),
                ),
              WText(
                text,
                style: TextStyle(
                    color: fontColor ?? (isBg ? Colors.white : color),
                    fontSize: fontSize.px,
                    height: 1.2),
              ),
            ],
          )),
    );
  }
}
